<template>
  <div
    v-if="pageData?.enrollConfig.afterEvent === 'showMessage'"
    class="t-center m15 success_text"
  >
    {{ metaInfo?.enrollConfig.showMessage || "提交成功！" }}
  </div>
  <div v-if="pageData.enrollConfig?.isShare === 'Y'" class="social-share m15">
    <van-button block type="primary" @click="shareSurvey()">分享</van-button>
  </div>
  <div v-if="pageData?.enrollConfig.isReview === 'Y'" class="m15">
    <van-button :to="{ name: 'EnrollView' }" block plain type="primary">
      查看已填内容
    </van-button>
  </div>
  <div v-if="pageData?.enrollConfig.showLottery === 'Y'" class="lottery">
    <img
      :src="pageData?.enrollConfig.lotteryIconUrl"
      alt=""
      @click="jumpToLimit"
    />
  </div>
</template>

<script setup>
import { enrollStore } from "@/stores/enroll";
import { jumpWeb, share } from "@/utils/common";
import { storeToRefs } from "pinia";

const store = enrollStore();
const { enrollInfo } = storeToRefs(store);
let pageData = enrollInfo.value.pageData || {};
const metaInfo = JSON.parse(pageData.metaInfo || "{}");
let obj = metaInfo.enrollConfig ? metaInfo.enrollConfig : {};
pageData.enrollConfig = { ...obj, ...pageData.enrollConfig };
console.log("报名enrollInfo", enrollInfo);
console.log("报名pageData", pageData);
if (pageData?.enrollConfig.afterEvent === "towardPage") {
  jumpWeb(pageData.enrollConfig.towardPage, "_self");
}
// 抽奖
const jumpToLimit = () => {
  jumpWeb(pageData.enrollConfig.lotteryAddr);
};
// 分享 生成二维码
const shareSurvey = () => {
  share(
    location.origin +
      "/member/enroll?token=#token#&type=h5&id=" +
      pageData.enrollConfig?.enrollId,
  );
};
</script>

<style lang="less" scoped>
.success_text {
  min-height: 10rem;
  display: flex;
  font-size: 32px;
  align-items: center;
  justify-content: center;
  word-break: break-all;
}

.lottery {
  text-align: center;
  margin-top: 4rem;

  & img {
    max-width: 100%;
    cursor: pointer;
  }
}
</style>
